import { reactive } from 'vue'

export function useDicts() {
    const status: any = [ // 上架审批状态
        {
            label: '全部',
            type: 'primary',
            value: 1,
        },
        {
            label: '审批中',
            type: 'warning',
            value: 2,
        },
        {
            label: '通过',
            type: 'success',
            value: 3,
        },
        {
            label: '驳回',
            type: 'danger',
            value: 4,
        },
    ]

    const houseStatus: any = [ // 企业等级
        {
            label: '赋编审核中',
            type: 'primary',
            value: 0,
        },
        {
            label: '空闲',
            type: 'success',
            value: 1,
        },
        {
            label: '锁定',
            type: 'info',
            value: 2,
        },
        {
            label: '租住中',
            type: 'warning',
            value: 3,
        },
        {
            label: '下架',
            type: 'danger',
            value: 4,
        },
        {
            label: '草稿',
            type: 'info',
            value: 5,
        },
    ]

    const zullx: any = [ // 租赁类型
        {
            label: '合租',
            value: 1,
        },
        {
            label: '整租',
            value: 2,
        },
    ]
    const fangylx: any = [ // 租赁类型
        {
            label: '保租房',
            value: 1,
        },
        {
            label: '公租房',
            value: 2,
        },
        {
            label: '人才公寓',
            value: 3,
        },
        {
            label: '市场化租赁',
            value: 4,
        },
    ]

    const dicts = reactive<any>({
        fangylx,
        houseStatus,
        status,
        zullx,
    })

    const useTag = (key: string, value: number | string, label: string) => {
        console.log('value---', value)
        console.log('label---', label)
        return dicts[key].find((v: any) => (String(v.value) === String(value) || v.label === label))
    }

    const useDict = (key: string, value: number | string, getLabel = true) => {
        let target = dicts[key].find((v: any) => v.value === value)?.label || value
        if (!getLabel)
            target = dicts[key].find((v: any) => v.label === value)?.value || value

        return target
    }

    return { dicts, useDict, useTag }
}
